# 以text格式读取xml
import re
import os
#找出所有文件中height和width为0的
width_fmat = re.compile(r'\t\t<width>0</width>')#定义想要删除的格式
height_fmat = re.compile(r'\t\t<height>0</height>')
path = '/Users/jiangce/Desktop/车型识别/VOCdevkit/'
pathxml = path + 'xml/'
pathimg = path + 'img/'
listdir = os.listdir(pathxml)
f = open('/Users/jiangce/Desktop/test11.txt','w')
for onedir in listdir:
    with open(pathxml + onedir) as fxml:
        content = fxml.readlines()
        for oneline in content:
            #print(type(i))
            if width_fmat.match(oneline):
                f.write(onedir)
                f.write('\n')
            elif height_fmat.match(oneline):
                f.write(onedir)
                f.write('\n')
f.close()
with open('/Users/jiangce/Desktop/widthAndheight0.txt','r') as f:
    listdel = f.readlines()
    print(len(listdel))
    for deldir in listdel:
        namedir = deldir.split('.')[0]
        print(namedir)
        try:
            os.remove(pathxml + namedir + '.xml')
            os.remove(pathimg + namedir + '.jpg')
        except:
            pass

